package com.gitee.flow.service;

import com.gitee.jmash.core.orm.tenant.TenantService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.io.IOException;
import jmash.flow.protobuf.BusinessStatusReq;
import jmash.flow.protobuf.DeployReq;
import jmash.flow.protobuf.DeployXmlReq;
import jmash.flow.protobuf.ProcInstDeleteReq;
import jmash.flow.protobuf.ProcInstSuspendReq;
import jmash.flow.protobuf.StartProcInstReq;
import jmash.flow.protobuf.TaskAssignReq;
import jmash.flow.protobuf.TaskAttachmentCreateReq;
import jmash.flow.protobuf.TaskAttachmentUpdateReq;
import jmash.flow.protobuf.TaskClaimReq;
import jmash.flow.protobuf.TaskDelegateReq;
import jmash.flow.protobuf.TaskGobackReq;
import jmash.flow.protobuf.TaskHandleReq;
import jmash.flow.protobuf.TaskPriorityReq;
import jmash.flow.protobuf.TaskResolveReq;
import jmash.flow.protobuf.TaskSuspendReq;
import org.checkerframework.checker.units.qual.N;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.task.Attachment;

/**
 * Flow服务Write接口.
 *
 * @author <a href="mailto:service@crenjoy.com">crenjoy</a>
 */
public interface FlowWrite extends TenantService {

  /** 部署流程. */
  Deployment deployFlow(@NotNull @Valid DeployReq req) throws IOException;

  /** 部署XML流程. */
  Deployment deployFlowXml(@NotNull @Valid DeployXmlReq req);

  /** 删除流程部署. */
  void deleteDeployment(@NotBlank String deploymentId);

  /** 启动流程实例. */
  ProcessInstance startProcInst(@NotNull @Valid StartProcInstReq request);

  /** 认领任务. */
  int claimTask(@NotNull @Valid TaskClaimReq req);

  /** 执行任务. */
  boolean completeTask(@NotNull @Valid TaskHandleReq req);

  /** 任务退回到选择节点. */
  boolean gobackTask(@NotNull @Valid TaskGobackReq req);

  /** 插入任务附件. */
  Attachment insertAttachment(@NotNull @Valid TaskAttachmentCreateReq attachment);

  /** 更新任务附件. */
  Attachment updateAttachment(@NotNull @Valid TaskAttachmentUpdateReq attachment);

  /** 删除任务附件. */
  Attachment deleteAttachment(@NotNull String attachmentId);
  
  /** 暂停/恢复流程实例. */
  boolean suspendProcInst(@NotNull @Valid ProcInstSuspendReq req);

  /** 删除流程实例. */
  boolean deleteProcInst(@NotNull @Valid ProcInstDeleteReq req);
  
  /** 暂停/恢复任务. */
  boolean suspendTask(@NotNull @Valid TaskSuspendReq req);
  
  /** 分配/移交任务给某人/候选人. */
  boolean assignTask(@NotNull @Valid TaskAssignReq req);
  
  /** 设置任务优先级. */
  boolean priorityTask(@NotNull @Valid TaskPriorityReq req);
  
  /** 委托用户办理任务,将owner设置为原用户，并DELEGATION_标记为pending状态。. */
  boolean delegateTask(@NotNull @Valid TaskDelegateReq req);
  
  /** 完成委托任务,并DELEGATION_标记状态为RESOLVED状态. */
  boolean resolveTask(@NotNull @Valid TaskResolveReq req);

  /** 设置业务状态. */
  boolean setBusinessStatus(@NotNull String procInstId, @NotNull String businessStatus);
  

}
